<?php
/**
 * controller file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/09/03
 * Time: 17:42
 */
namespace Modules\Shop\Http\Controllers;

use HiCommon\Service\ShopCheckpointServiceSpecsService;
use Illuminate\Support\Facades\Request;

class ShopCheckpointServiceSpecsController extends BaseController
{

    /**
     *  检车站规格 列表
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function index()
    {
        try {
            $arr_where = ['shop_id'=>shop_shop_id()];
            $res = ShopCheckpointServiceSpecsService::get_list_by_shopid($arr_where);
            echo_error($res);
            return view('shop::shop_checkpoint_service_specs.index', ['arr_data'=>$res['data']]);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 添加 检车站规格 页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function create()
    {
        return view('shop::shop_checkpoint_service_specs.create');
    }

    /**
     * 添加 检车站规格 操作
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function store()
    {
        try {
            $arr_input = Request::input();
            $arr_input['shop_id'] = (int)shop_shop_id();
            return ShopCheckpointServiceSpecsService::add_one($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 修改 检车站规格 页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit()
    {
       try {
           $nId = Request::get('id',0);
           $res = ShopCheckpointServiceSpecsService::get_one((int)$nId);
           echo_error($res);

           $arr_data = [
             'arr_data'=>$res['data'],
           ];
           return view('shop::shop_checkpoint_service_specs.edit',$arr_data);
       }
       catch (\Exception $exception) {
           return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
       }
    }

    /**
     * 修改 检车站规格 页面操作
     *
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function update()
    {
        try {
            $arr_input = Request::input();
            return ShopCheckpointServiceSpecsService::edit_one($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 添加 检车站规格参数 页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function params_create()
    {
       try {
           $n_id = (int) Request::input('id');
           if($n_id <= 0){
               msg_error('操作id不能为空');
           }
           return view('shop::shop_checkpoint_service_specs.params_create',['n_id'=>$n_id]);
       }
       catch (\Exception $exception) {
           return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
       }
    }

    /**
     * 添加 检车站规格参数 操作
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function params_store()
    {
        try {
            $arr_input = Request::input();
            $arr_input['shop_id'] = (int)shop_shop_id();
            return ShopCheckpointServiceSpecsService::add_one($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }


    /**
     * 更改 检车站规格 状态
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function change_state()
    {
        try {
            $arr_input = Request::input();
            return ShopCheckpointServiceSpecsService::change_one_state($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 删除 检车站规格
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function delete()
    {
        try {
            $n_id = (int)Request::get('id',0);
            return ShopCheckpointServiceSpecsService::delete_one($n_id);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 检测站价目表 列表
     *
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function product_list()
    {
        try {
            $arr_where = ['shop_id'=>shop_shop_id()];
            $res = ShopCheckpointServiceSpecsService::get_list_by_shopid_for_dikaer($arr_where);

            //            dd($res);
            /* $arr_where = ['shop_id'=>shop_shop_id()];
             $res = ShopCheckpointServiceProductService::get_list_by_shopid($arr_where);*/
            echo_error($res);
            return view('shop::shop_checkpoint_service_specs.product_list', $res);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }

    }
}